<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\SmsService;
use Illuminate\Http\Request;

class SmsController extends Controller
{
    protected $SmsService;
    public function __construct(SmsService $SmsService)
    {
        $this->SmsService = $SmsService;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $Request){
        if(!$Request->mobile){
            return response()->json(['code' => '403', 'message' => '请输入用户名']);
        }
        $data = User::where('mobile',$Request->mobile)->first();
        if(!$data){
            return response()->json(['code' => '404', 'message' => '账号不存在']);
        }
        $code = '';
        $code = rand(1000, 9999);
        $data = $this->SmsService->sendWithLimit($Request->mobile,'您登录的验证码是:'.$code.',有效期2分钟');
        return response()->json(['code' => 200, 'message' => 'success','data'=>$data['success']]);
    }
}
